<?php

namespace App\Admin\Controllers;

use App\Models\GoldRound;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;
use \App\Models\ConfigStorm;

class ConfigStormsController extends AdminController
{
    protected $title = '黄金风暴配置';

    protected function form()
    {
        $form = new Form(new ConfigStorm());

        $form->checkbox('rest_weekdays', '风暴休息日')->options(config('site.weekdays'))->default(['Sat', 'Sun']);

        $form->divider();

	    $form->radio('is_gold_support_open', '开启扶持')->options(config('site.bool'))->default(false);
	    $form->currency('gold_support_beans', '扶持金豆数')->symbol('￥')->default(100.00)->rules('required|min:0');
	    $form->currency('gold_support_coins', '扶持余额金')->symbol('￥')->default(100.00)->rules('required|min:0');
	    $form->currency('gold_support_cashes', '扶持抢购金')->symbol('￥')->default(1000.00)->rules('required|min:0');
	    $form->currency('a_gold_bean_buy_cashes', '每金豆购买抢购金')->symbol('￥')->default(100.00)->rules('required|min:0');

	    $form->divider();

        $form->number('each_upgrade_needs_children', '炼金师升级人数')->default(10)->rules('required|min:0');
        $form->currency('allowed_lowest_transfer_gold_beans', '金豆最低转出额度')->symbol('￥')->default(100.00)->rules('required|min:0');
        $form->currency('allowed_lowest_transfer_gold_coins', '黄金账户最低转出')->symbol('￥')->default(100.00)->rules('required|min:0');

        $form->divider();

        $form->rate('round_premium_percent', '每轮商品溢价')->default(8.00)->rules('required|min:0|max:100');
        $form->rate('resell_need_beans_percent', '寄卖要求金豆')->default(3.00)->rules('required|min:0|max:100');
        $form->rate('move_round_profit_percent', '正常寄卖利润')->default(4.00)->rules('required|min:0|max:100');
        $form->rate('last_round_profit_percent', '拆单寄卖利润')->default(24.00)->rules('required|min:0|max:100');

        $form->divider();

	    $form->decimal('child_first_record_give_direct_parent_cashes', '直邀1位见习奖抢购金')->default(1000.00)->rules('required|min:0');
	    $form->rate('child_record_give_direct_parent_master_prize_percent', '炼金师直推奖励比例')->default(2.00)->rules('required|min:0|max:100');
	    $form->rate('child_record_give_direct_parent_intern_prize_percent', '见习直推奖励比例')->default(1.00)->rules('required|min:0|max:100');

        $form->rate('child_record_give_team_parent_masters_prize_percent', '炼金师团队奖励比例')->default(1.00)->rules('required|min:0|max:100');
        $form->number('child_record_give_team_parent_masters_amount', '炼金师团队奖励层级')->default(3)->rules('required|min:0');

        $form->divider();

        $form->number('pay_code_can_try', '交易密码试错')->default(3)->rules('required|min:0|max:3');
        $form->number('pay_gold_record_must_within_minutes', '抢购付款周期/分钟')->default(15)->rules('required|min:0');
        $form->radio('is_overcome_pay_fine', '关单是否罚豆')->options(config('site.bool'))->default(false);

	    $form->divider();

        $form->number('take_back_gold_product_within_minutes', '机器回购开始/分钟')->default(10)->min(3)->max(45)->rules('required|min:0');
        $form->number('terminate_gold_product_within_minutes', '机器终结开始/分钟')->default(3)->min(3)->max(45)->rules('required|min:0');

	    $form->divider();

	    $form->radio('is_robot_on', '允许机器人启动')->options(config('site.bool'))->default(true);
	    $form->radio('is_reclaim_on', '允许机器人回收')->options(config('site.bool'))->default(true);
	    $form->radio('is_terminate_on', '允许机器人终结')->options(config('site.bool'))->default(true);

	    $this->formTools($form);
	    $this->formFooter($form);
	    $this->formSaved($form);

        return $form;
    }

	protected function formTools(Form $form)
	{
		$form->tools(function (Form\Tools $tools) {
			$tools->disableList();
			$tools->disableView();
			$tools->disableDelete();
		});
	}

	protected function formFooter(Form $form)
	{
		$form->footer(function (Form\Footer $footer) {
			$footer->disableReset();
			$footer->disableViewCheck();
			$footer->disableCreatingCheck();
			$footer->disableEditingCheck();
		});
	}

	protected function formSaved(Form $form)
	{
		$form->saved(function () {
			admin_toastr('会员促销配置', 'success');
			return redirect(route('admin.config-storms.edit', 1));
		});
	}
}
